package v3

import (
	"fmt"
	"os"
)

const Usage = `
createBlockChain --address ADDRESS "create a blockchian"
addBlock --data DATA "add a block"
printChain "print block Chain"
`

type CLI struct {
}

func (cli *CLI) Run() {
	args := os.Args
	length := len(args)
	if length < 2 {
		fmt.Println(Usage)
		return
	}
	//第二个参数
	cmd := args[1]
	switch cmd {
	case "createBlockChain":
		if length < 4 {
			fmt.Println(Usage)
			return
		}
		check := args[2]
		if check != "--address" {
			fmt.Println(Usage)
			fmt.Println("--address 不存在")
			return
		}
		cli.createBlockChain(args[3])
	case "addBlock":
		if length < 4 {
			fmt.Println(Usage)
			return
		}
		check := args[2]
		if check != "--data" {
			fmt.Println(Usage)
			fmt.Println("--data 不存在")
			return
		}
		cli.addBlock(args[3])
	case "printChain":
		cli.printChain()
	default:
		fmt.Println(Usage)
	}
}
